package com.zbkj.crmeb.export.service.impl;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.common.PageParamRequest;
import com.constants.Constants;
import com.crmeb.core.exception.CrmebException;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.util.StringUtil;
import com.utils.CrmebUtil;
import com.utils.DateUtil;
import com.utils.PriceUtil;
import com.zbkj.crmeb.agent.request.SettlementRequest;
import com.zbkj.crmeb.agent.response.SettlementResponse;
import com.zbkj.crmeb.agent.service.AgentAccountService;
import com.zbkj.crmeb.agent.service.AgentService;
import com.zbkj.crmeb.category.service.CategoryService;
import com.zbkj.crmeb.chant.model.CategoryMatch;
import com.zbkj.crmeb.chant.model.ChannelMerchant;
import com.zbkj.crmeb.chant.response.AccountCenterResponse.Bill;
import com.zbkj.crmeb.chant.service.ICategoryMatchService;
import com.zbkj.crmeb.chant.service.IChannelMerchantAccountService;
import com.zbkj.crmeb.chant.service.IChannelMerchantService;
import com.zbkj.crmeb.enums.AccountFlowTypeEnum;
import com.zbkj.crmeb.enums.OrderStatusEnum;
import com.zbkj.crmeb.enums.StockAreaTempEnum;
import com.zbkj.crmeb.export.service.ExcelService;
import com.zbkj.crmeb.export.vo.LogisticsExcelVo;
import com.zbkj.crmeb.export.vo.MerFlowExcelVo;
import com.zbkj.crmeb.export.vo.ProductExcelVo;
import com.zbkj.crmeb.export.vo.StoreProductCodeExcelVo;
import com.zbkj.crmeb.export.vo.StoreProductNormCodeExcelVo;
import com.zbkj.crmeb.export.vo.StoreProductNormExcelVo;
import com.zbkj.crmeb.finance.request.GetListRequest;
import com.zbkj.crmeb.finance.response.UserRechargeResponse;
import com.zbkj.crmeb.finance.service.UserRechargeService;
import com.zbkj.crmeb.store.model.OrderInfoDelivery;
import com.zbkj.crmeb.store.model.PurchaseGoods;
import com.zbkj.crmeb.store.model.StoreOrder;
import com.zbkj.crmeb.store.model.StoreOrderInfo;
import com.zbkj.crmeb.store.model.StoreProductAttrValue;
import com.zbkj.crmeb.store.model.StoreProductNorm;
import com.zbkj.crmeb.store.model.Supplier;
import com.zbkj.crmeb.store.request.StoreProductSearchRequest;
import com.zbkj.crmeb.store.response.StoreCartResponse;
import com.zbkj.crmeb.store.response.StoreProductCartProductInfoResponse;
import com.zbkj.crmeb.store.response.StoreProductNormKeywordResponse;
import com.zbkj.crmeb.store.response.StoreProductResponse;
import com.zbkj.crmeb.store.service.OrderInfoDeliveryService;
import com.zbkj.crmeb.store.service.PurchaseGoodsService;
import com.zbkj.crmeb.store.service.StoreBrandService;
import com.zbkj.crmeb.store.service.StoreOrderService;
import com.zbkj.crmeb.store.service.StoreProductRelationService;
import com.zbkj.crmeb.store.service.StoreProductService;
import com.zbkj.crmeb.store.service.SupplierService;
import com.zbkj.crmeb.upload.service.AsyncService;

import cn.hutool.core.bean.BeanUtil;

/**
* @author Mr.Zhang
* @Description ExcelServiceImpl 接口实现
* @since 2020-05-06
*/
@Service
public class ExcelServiceImpl implements ExcelService {
    @Autowired
    private StoreProductService storeProductService;
    @Autowired
    private CategoryService categoryService;
    @Autowired
    private StoreProductRelationService storeProductRelationService;
    @Autowired
    private StoreBrandService storeBrandService;
    @Autowired
    AsyncService asyncService;
    @Autowired
    IChannelMerchantAccountService channelMerchantAccountService;
    @Autowired
    UserRechargeService userRechargeService;
    @Autowired
    ICategoryMatchService categoryMatchService;
    @Autowired
    PriceUtil priceUtil;
    @Autowired
    StoreOrderService storeOrderService;
    @Autowired
    IChannelMerchantService channelMerchantService;
    @Autowired
    SupplierService supplierService;
    @Autowired
    OrderInfoDeliveryService orderInfoDeliveryService;
    @Autowired
    PurchaseGoodsService purchaseGoodsService;
    @Autowired
    AgentAccountService agentAccountService;
    @Autowired
    AgentService agentService;

    /**
     * 商品列表导出
     * @param request 请求参数
     * @author Mr.Zhang
     * @since 2020-05-06
     */
    @Override
    public List<ProductExcelVo> product(StoreProductSearchRequest request) {
        PageParamRequest pageParamRequest = new PageParamRequest();
        pageParamRequest.setPage(Constants.DEFAULT_PAGE);
        pageParamRequest.setLimit(Constants.EXPORT_MAX_LIMIT);
        PageInfo<StoreProductResponse> storeProductResponsePageInfo = storeProductService.getList(request, pageParamRequest);
        List<StoreProductResponse> list = storeProductResponsePageInfo.getList();
        if(list.size() < 1){
            throw new CrmebException("没有可导出的数据！");
        }

        //从集合中取出ID
        List<Integer> idList = list.stream().map(StoreProductResponse::getId).distinct().collect(Collectors.toList());

        //产品分类id
        List<Integer> cateIdListStr = list.stream().map(StoreProductResponse::getCateId).distinct().collect(Collectors.toList());

        HashMap<Integer, String> categoryNameList = new HashMap<Integer, String>();
        if(cateIdListStr.size() > 0){
            String join = StringUtils.join(cateIdListStr, ",");
            List<Integer> cateIdList = CrmebUtil.stringToArray(join);
            categoryNameList = categoryService.getListInId(cateIdList);
        }

        //点赞
        HashMap<Integer, Integer> likeCount = storeProductRelationService.getLikeCountListInProductId(idList);

        //收藏
        HashMap<Integer, Integer> collectCount = storeProductRelationService.getCollectCountListInProductId(idList);

        ArrayList<ProductExcelVo> productExcelVoList = new ArrayList<>();
        for (StoreProductResponse storeProductResponse : list ) {
//            productExcelVoList.add(
//                    new ProductExcelVo(
//                            storeProductResponse.getStoreName(),
//                            storeProductResponse.getStoreInfo(),
//                            CrmebUtil.getValueByIndex(categoryNameList, storeProductResponse.getCateId()),
//                            storeProductResponse.getPrice(),
//                            storeProductResponse.getSales(),
//                            storeProductResponse.getStock(),
//                            CrmebUtil.getIntValueByIndex(likeCount, storeProductResponse.getId()),
//                            CrmebUtil.getIntValueByIndex(collectCount, storeProductResponse.getId())
//                    )
//            );
        }
        return productExcelVoList;
    }


    @Override
    public List<StoreProductNormExcelVo> convertStoreProductNormList(List<StoreProductNorm> list) {
        List<StoreProductNormExcelVo> normExcelVoList = new ArrayList<>();
        list.forEach(n ->{
            StoreProductNormExcelVo normExcelVo = new StoreProductNormExcelVo();
            BeanUtil.copyProperties(n, normExcelVo);
            String imgUrl = normExcelVo.getImage();
            imgUrl = StringUtil.isEmpty(imgUrl) ? "" : imgUrl.substring(0, -1 == imgUrl.indexOf("?") ? imgUrl.length() : imgUrl.indexOf("?"))+"?x-oss-process=image/resize,m_fill,w_100,h_100";
            normExcelVo.setImage(imgUrl);
            normExcelVo.setCreateTime(DateUtil.dateToStr(n.getCreateTime(),Constants.DATE_FORMAT));
            normExcelVo.setUpdateTime(DateUtil.dateToStr(n.getUpdateTime(),Constants.DATE_FORMAT));
            normExcelVoList.add(normExcelVo);
        });
        return normExcelVoList;
    }

    @Override
    public List<StoreProductNormCodeExcelVo> convertNormCodeList(List<StoreProductNorm> list) {
        List<StoreProductNormCodeExcelVo> normExcelVoList = new ArrayList<>();
        list.forEach(n ->{
            StoreProductNormCodeExcelVo normCodeExcelVo = new StoreProductNormCodeExcelVo();
            BeanUtil.copyProperties(n, normCodeExcelVo);
            normCodeExcelVo.setCreateTime(DateUtil.dateToStr(n.getCreateTime(),Constants.DATE_FORMAT));
            normCodeExcelVo.setUpdateTime(DateUtil.dateToStr(n.getUpdateTime(),Constants.DATE_FORMAT));
            normExcelVoList.add(normCodeExcelVo);
        });
        return normExcelVoList;
    }

    @Override
    public List<StoreProductCodeExcelVo> convertProductCodeList(List<StoreProductNormKeywordResponse> list) {
        List<StoreProductCodeExcelVo> productCodeList = new ArrayList<>();
        list.forEach(n ->{
            StoreProductCodeExcelVo productCodeExcelVo = new StoreProductCodeExcelVo();
            BeanUtil.copyProperties(n, productCodeExcelVo);
            productCodeExcelVo.setCreateTime(DateUtil.dateToStr(n.getCreateTime(),Constants.DATE_FORMAT));
            productCodeList.add(productCodeExcelVo);
        });
        return productCodeList;
    }

    @Override
    public void parseList(List<ProductExcelVo> list) {
        if(CollectionUtils.isEmpty(list)){
            return;
        }

        //从集合中取出ID
        List<Integer> idList = list.stream().map(ProductExcelVo::getBrandId).distinct().collect(Collectors.toList());
        Map<Integer,String> brandMap = storeBrandService.getBrandNameMap(idList);

        // 处理category数据
        List<CategoryMatch> categoryMatchList = categoryMatchService.list(Wrappers.<CategoryMatch>lambdaQuery().eq(CategoryMatch::getType, 1));
        Map<Integer, CategoryMatch> categoryMatchMap = categoryMatchList.stream().collect(Collectors.toMap(CategoryMatch::getId, s -> s));
        for (ProductExcelVo excelVo : list) {
            // 商品标签处理
            List<Integer> productCateIds = Collections.singletonList(excelVo.getCateId());
            StringBuilder sb = new StringBuilder();
            for(int i=0; i<productCateIds.size(); i++) {
                CategoryMatch category = categoryMatchMap.get(productCateIds.get(i));
                sb.append(null == category ? "" : category.getName());
                if(i <productCateIds.size()-1) {
                    sb.append(",");
                }
            }
            excelVo.setCreateTime(excelVo.getCreateTime());
            excelVo.setCateName(sb.toString());
            //发货地处理
            excelVo.setTempName(Objects.requireNonNull(StockAreaTempEnum.valueOf(excelVo.getTempId())).getStockAreaName());
            //价格处理
            excelVo.setPriceEur(priceUtil.rmb2EurStatic(excelVo.getAttrPrice(), excelVo.getExchangeRate()));
            excelVo.setOtPriceRmb(priceUtil.eur2RmbStatic(excelVo.getAttrOtPrice(), excelVo.getExchangeRate()));
            excelVo.setCostEUR(priceUtil.rmb2EurStatic(excelVo.getAttrCost(),excelVo.getExchangeRate()));
            // 图片压缩
            String imgUrl = excelVo.getImage();
            imgUrl = StringUtil.isEmpty(imgUrl) ? "" : imgUrl.substring(0, !imgUrl.contains("?") ? imgUrl.length() : imgUrl.indexOf("?"))+"?x-oss-process=image/resize,m_fill,w_100,h_100";
            excelVo.setImage(imgUrl);
        }
    }

    /**
     * 商户流水列表导出
     * @param merId
     * @param type
     * @param request
     * @return
     */
    @Override
    public List<MerFlowExcelVo> getMerFlowList(Integer merId, Integer type, PageParamRequest request) {
        PageHelper.startPage(request.getPage(), request.getLimit());
        List<Bill> flowList = channelMerchantAccountService.getFlowList(merId, type);
        List<MerFlowExcelVo> list = new ArrayList<>();
        flowList.forEach(e->{
            MerFlowExcelVo merFlowExcelVo = new MerFlowExcelVo();
            if (AccountFlowTypeEnum.PRODUCT.getCode().equals(e.getTradeType()) && CollectionUtils.isNotEmpty(e.getProductList())) {
                e.getProductList().forEach(product->{
                    StoreProductCartProductInfoResponse productInfo = product.getInfo().getProductInfo();
                    merFlowExcelVo.setBrandName(productInfo.getBrandName())
                            .setImage(productInfo.getImage())
                            .setKeyword(productInfo.getKeyword())
                            .setStoreName(productInfo.getStoreName())
                            .setSuk(productInfo.getAttrInfo().getSuk());

                });
            }
            BeanUtil.copyProperties(e,merFlowExcelVo,"createTime");
            merFlowExcelVo.setCreateTime(DateFormatUtils.format(e.getCreateTime(), "yyyy-MM-dd HH:mm:ss"));
            list.add(merFlowExcelVo);
        });
        return list;
    }

    /**
     * 商户结算数据导出
     * @param request
     * @return
     */
    @Override
    public List<UserRechargeResponse> getMerSettlementList(GetListRequest request) {
        return userRechargeService.getListByTradeType(request);
    }

    @Override
    public List<LogisticsExcelVo> logisticsExport(List<StoreOrderInfo> logisticsList) {
        List<LogisticsExcelVo> list = new ArrayList<>();
        if(CollectionUtils.isEmpty(logisticsList)){
            return list;
        }
        Set<Integer> orderIdList = logisticsList.stream().map(StoreOrderInfo::getOrderId).collect(Collectors.toSet());
        List<StoreOrder> storeOrderList = storeOrderService.list(Wrappers.lambdaQuery(StoreOrder.class).in(StoreOrder::getId, orderIdList).orderByDesc(StoreOrder::getId));
        Map<Integer, StoreOrder> storeOrderMap = storeOrderList.stream().collect(Collectors.toMap(StoreOrder::getId, e -> e));
        List<ChannelMerchant> merList = channelMerchantService.list(Wrappers.lambdaQuery(ChannelMerchant.class).in(ChannelMerchant::getId, storeOrderList.stream().map(StoreOrder::getMerId).distinct().collect(Collectors.toList())));
        Map<Integer, ChannelMerchant> merMap = merList.stream().collect(Collectors.toMap(ChannelMerchant::getId, e -> e));
        Set<Integer> actualSupplierIdList = logisticsList.stream().map(StoreOrderInfo::getActualSupplierId).collect(Collectors.toSet());
        List<Supplier> supplierList = supplierService.list(Wrappers.lambdaQuery(Supplier.class).in(Supplier::getId, actualSupplierIdList));
        Map<Integer, String> supplierMap = supplierList.stream().collect(Collectors.toMap(Supplier::getId, Supplier::getSuppliersName));
        for (StoreOrderInfo storeOrderInfo : logisticsList) {
            StoreCartResponse storeCartResponse = JSON.parseObject(storeOrderInfo.getInfo(), StoreCartResponse.class);
            StoreProductCartProductInfoResponse productInfo = storeCartResponse.getProductInfo();
            StoreProductAttrValue attrInfo = productInfo.getAttrInfo();
            StoreOrder storeOrder = storeOrderMap.get(storeOrderInfo.getOrderId());
            LogisticsExcelVo logisticsExcelVo = new LogisticsExcelVo();
            logisticsExcelVo.setOrderStatus(OrderStatusEnum.valueOf(storeOrderInfo.getStatus()).getMsg());
            logisticsExcelVo.setOrderNumber(storeOrder.getOrderId());
            logisticsExcelVo.setMerName(merMap.get(storeOrder.getMerId()).getChannelName());
            logisticsExcelVo.setChildOrderNumber(storeOrderInfo.getChildOrderNumber());
            logisticsExcelVo.setProductId(storeCartResponse.getProductId());
            logisticsExcelVo.setProductName(productInfo.getStoreName());
            logisticsExcelVo.setBrandName(productInfo.getBrandName());
            //图片压缩
            String imgUrl = productInfo.getImage();
            imgUrl = StringUtil.isEmpty(imgUrl) ? "" : imgUrl.substring(0, !imgUrl.contains("?") ? imgUrl.length() : imgUrl.indexOf("?"))+"?x-oss-process=image/resize,m_fill,w_100,h_100";
            logisticsExcelVo.setImage(imgUrl);
            logisticsExcelVo.setKeyword(productInfo.getKeyword());
            logisticsExcelVo.setColorCode(attrInfo.getColorCode());
            if(StringUtils.isNotBlank(attrInfo.getAttrValue())){
                JSONObject jsonObject = JSONObject.parseObject(attrInfo.getAttrValue());
                List<Object> collect = Stream.of(jsonObject.get("尺寸"), jsonObject.get("尺码"), jsonObject.get("大小"), jsonObject.get("腰带尺寸")).collect(Collectors.toList());
                collect.removeIf(Objects::isNull);
                logisticsExcelVo.setSize(CollectionUtils.isEmpty(collect) ? null : collect.get(0).toString());
            }
            logisticsExcelVo.setQuantity(storeCartResponse.getCartNum());
            logisticsExcelVo.setActualCost(storeOrderInfo.getActualCost());
            logisticsExcelVo.setActualCostEur(storeOrderInfo.getActualCostEur());
            if(storeOrderInfo.getActualSupplierId() != null){
                logisticsExcelVo.setActualSupplierName(supplierMap.get(storeOrderInfo.getActualSupplierId()));
            }
            //实际发货地
            if (Objects.nonNull(storeOrderInfo.getActualStockAreaCode())) {
                StockAreaTempEnum stockAreaTempEnum = StockAreaTempEnum.valueOf(storeOrderInfo.getActualStockAreaCode());
                logisticsExcelVo.setActualTempName(Objects.isNull(stockAreaTempEnum) ? null : stockAreaTempEnum.getStockAreaName());
            }
            logisticsExcelVo.setPrice(attrInfo.getPrice());
            logisticsExcelVo.setFirstPrice(attrInfo.getFirstPrice());
            logisticsExcelVo.setSecondPrice(attrInfo.getSecondPrice());
            logisticsExcelVo.setTaxPrice(attrInfo.getTaxPrice());
            //采购商订单号
            List<PurchaseGoods> purchaseGoodsList = purchaseGoodsService.list(Wrappers.lambdaQuery(PurchaseGoods.class).eq(PurchaseGoods::getStoreOrderInfoId, storeOrderInfo.getId()).eq(PurchaseGoods::getPushStatus, 1));
            if(CollectionUtils.isNotEmpty(purchaseGoodsList)){
                Map<Integer, List<PurchaseGoods>> purchaseMap = purchaseGoodsList.stream().collect(Collectors.groupingBy(PurchaseGoods::getPushType));
                StringBuilder str = new StringBuilder();
                for (Entry<Integer, List<PurchaseGoods>> entry : purchaseMap.entrySet()) {
                    if(entry.getKey() == 0){
                        str.append("系统推送:").append(entry.getValue().stream().map(PurchaseGoods::getChannelOrderSn).collect(Collectors.joining(",")));
                    }else {
                        str.append(",手动推送:").append(entry.getValue().stream().map(PurchaseGoods::getChannelOrderSn).collect(Collectors.joining(",")));
                    }
                }
                logisticsExcelVo.setBuyerOrderNo(str.toString());
            }
            //物流部门物流信息
            List<OrderInfoDelivery> infoDeliveryList = orderInfoDeliveryService.list(Wrappers.lambdaQuery(OrderInfoDelivery.class).eq(OrderInfoDelivery::getOrderInfoId, storeOrderInfo.getId()).eq(OrderInfoDelivery::getChannel, 2));
            if(CollectionUtils.isNotEmpty(infoDeliveryList)){
                Map<String, List<OrderInfoDelivery>> infoDeliveryMap = infoDeliveryList.stream().collect(Collectors.groupingBy(OrderInfoDelivery::getName));
                for (Entry<String, List<OrderInfoDelivery>> entry : infoDeliveryMap.entrySet()) {
                    String deliveryCompany = entry.getValue().stream().map(OrderInfoDelivery::getDeliveryCompany).collect(Collectors.joining(" / "));
                    String time = entry.getValue().stream().map(OrderInfoDelivery::getCreateTime).map(e -> DateFormatUtils.format(e, "yyyy-MM-dd HH:mm:ss")).collect(Collectors.joining(" / "));
                    String deliveryNumber = entry.getValue().stream().map(OrderInfoDelivery::getDeliveryNumber).collect(Collectors.joining(" / "));
                    switch (entry.getKey()){
                        case "海外直邮":
                            logisticsExcelVo.setOdmLogistics(deliveryCompany);
                            logisticsExcelVo.setOdmTime(time);
                            logisticsExcelVo.setOdmOrderNo(deliveryNumber);
                            break;
                        case "海外发往中转仓":
                            logisticsExcelVo.setOtwLogistics(deliveryCompany);
                            logisticsExcelVo.setOtwTime(time);
                            logisticsExcelVo.setOtwOrderNo(deliveryNumber);
                            break;
                        case "中转仓发出":
                            logisticsExcelVo.setTwdLogistics(deliveryCompany);
                            logisticsExcelVo.setTwdTime(time);
                            logisticsExcelVo.setTwdOrderNo(deliveryNumber);
                            break;
                        case "清关中":
                            logisticsExcelVo.setClearanceLogistics(deliveryCompany);
                            logisticsExcelVo.setClearanceTime(time);
                            logisticsExcelVo.setClearanceOrderNo(deliveryNumber);
                            break;
                        case "国内派送":
                            logisticsExcelVo.setDomesticLogistics(deliveryCompany);
                            logisticsExcelVo.setDomesticTime(time);
                            logisticsExcelVo.setDomesticOrderNo(deliveryNumber);
                            break;
                        case "清关异常":
                            logisticsExcelVo.setAbnormalClearanceLogistics(deliveryCompany);
                            logisticsExcelVo.setAbnormalClearanceTime(time);
                            logisticsExcelVo.setAbnormalClearanceOrderNo(deliveryNumber);
                            break;
                        default:
                            break;
                    }
                }
            }
//            logisticsExcelVo.setActualTaxAndSecondPrice(storeOrderInfo.getActualTaxAndSecondPrice());
            //收货人信息
            logisticsExcelVo.setRealName(storeOrder.getRealName());
            logisticsExcelVo.setUserPhone(storeOrder.getUserPhone());
            logisticsExcelVo.setDetail(storeOrder.getUserAddress());
            logisticsExcelVo.setIdCard(storeOrder.getIdCard());
            //季度
            logisticsExcelVo.setSeasonCode(attrInfo.getSeasonCode());
            // 运税费
            logisticsExcelVo.setTaxInternationalPrice(storeOrderInfo.getTaxInternationalPrice());
            logisticsExcelVo.setTaxTurnInlandPrice(storeOrderInfo.getTaxTurnInlandPrice());
            logisticsExcelVo.setTaxInlandDeliveryPrice(storeOrderInfo.getTaxInlandDeliveryPrice());
            logisticsExcelVo.setTaxTaxesPrice(storeOrderInfo.getTaxTaxesPrice());
            logisticsExcelVo.setActualTaxAndSecondPrice(storeOrderInfo.getTaxTaxesPrice()
                    .add(storeOrderInfo.getTaxInlandDeliveryPrice())
                    .add(storeOrderInfo.getTaxInternationalPrice())
                    .add(storeOrderInfo.getTaxTurnInlandPrice()));
            list.add(logisticsExcelVo);
        }
        return list;
    }

    @Override
    public List<MerFlowExcelVo> getAgentFlowList(Integer agentId, Integer type, PageParamRequest request) {
        PageHelper.startPage(request.getPage(), request.getLimit());
        List<Bill> flowList = agentAccountService.getFlowList(agentId, type);
        List<MerFlowExcelVo> list = new ArrayList<>();
        flowList.forEach(e->{
            MerFlowExcelVo merFlowExcelVo = new MerFlowExcelVo();
            if(AccountFlowTypeEnum.PRODUCT.getCode().equals(e.getTradeType()) && CollectionUtils.isNotEmpty(e.getProductList())){
                e.getProductList().forEach(product->{
                    StoreProductCartProductInfoResponse productInfo = product.getInfo().getProductInfo();
                    merFlowExcelVo.setBrandName(productInfo.getBrandName())
                            .setImage(productInfo.getImage())
                            .setKeyword(productInfo.getKeyword())
                            .setStoreName(productInfo.getStoreName())
                            .setSuk(productInfo.getAttrInfo().getSuk());
                });
            }
            BeanUtil.copyProperties(e,merFlowExcelVo,"createTime");
            merFlowExcelVo.setCreateTime(DateFormatUtils.format(e.getCreateTime(), "yyyy-MM-dd HH:mm:ss"));
            list.add(merFlowExcelVo);
        });
        return list;
    }

    @Override
    public List<SettlementResponse> getAgentSettlementList(SettlementRequest request) {
        return agentService.settlement(request);
    }

}

